package com.stottlerhenke.simbionic.api;

import java.util.HashMap;

import com.stottlerhenke.simbionic.common.Enum;


public class SB_VarType extends Enum {

  public SB_VarType(int state) { super(state);}

  public static final SB_VarType kNoSuchName = new SB_VarType(-4);
  public static final SB_VarType kStaticClass = new SB_VarType(-3);
  public static final SB_VarType kVoid = new SB_VarType(-2);
  public static final SB_VarType kInvalid = new SB_VarType(-1);
  public static final SB_VarType kFloat = new SB_VarType(0);
  public static final SB_VarType kString = new SB_VarType(1);
  public static final SB_VarType kEntity = new SB_VarType(2);
  public static final SB_VarType kVector = new SB_VarType(3);
  public static final SB_VarType kData = new SB_VarType(4);
  public static final SB_VarType kAny = new SB_VarType(5);
  public static final SB_VarType kInteger = new SB_VarType(6);
  public static final SB_VarType kBoolean = new SB_VarType(7);
  public static final SB_VarType kArray = new SB_VarType(8);
  public static final SB_VarType kTable = new SB_VarType(9);
  public static final SB_VarType kLAST_VARTYPE = new SB_VarType(10);
  
  //Java primitives not included in SimBionic
  public static final SB_VarType kShort = new SB_VarType(64);
  public static final SB_VarType kByte = new SB_VarType(65);
  public static final SB_VarType kChar = new SB_VarType(66);
  public static final SB_VarType kDouble = new SB_VarType(67);
  
  //Base and user defined classes
  public static final SB_VarType kCLASS_START = new SB_VarType(127);
  public static final SB_VarType kClass = new SB_VarType(256);

  public static SB_VarType getTypeFromInt(int value){
    switch(value){
      case -1: return kInvalid;
      case 0: return kFloat;
      case 1: return kString;
      case 2: return kEntity;
      case 3: return kVector;
      case 4: return kData;
      case 5: return kAny;
      case 6: return kInteger;
      case 7: return kBoolean;
      case 8: return kArray;
      case 9: return kTable;
      case 10: return kLAST_VARTYPE;
    }
    
    if( value >= kCLASS_START.getState() )
    {
      SB_VarType returnValue = (SB_VarType) _classTypes.get(new Integer(value));
      if( returnValue == null)
      {
        returnValue = new SB_VarType(value);
        _classTypes.put(new Integer(value), returnValue);
      }
      
      return returnValue;
    }
    
    return null;
  }
  
  static HashMap _classTypes = new HashMap(); //Key: Integer, Value: SB_VarType
}